<!DOCTYPE html>
<html>

<head lang="en">
    <title>找攻略</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategyComment.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/jquery-confirm/css/jquery-confirm.css">
    <script src="/js/plugins/jquery-confirm/js/jquery-confirm.js"></script>
    <script src="/js/common.js"></script>
    <script src="js/plugins/dialog2/dialog.min.js"></script>
    <link rel="stylesheet" href="js/plugins/dialog2/dialog.css">

    <script>
        $(function () {
            // 1获取url上面strategyCommentId
            var id = getParams().id;
            // 2根据strategyCommentId查询数据库获取当前攻略点评详细
            // 3.接口设计
            /**
             * 1.资源:/strategyComments/{id}
             * 2.请求方式:GET
             * 3.请求参数:
             * 4.返回结果: List<StrategyComment> JSON
             */
            $.get('/strategyComments/' + id, function (data) {
                console.log(data);
                // 渲染当前指定攻略点评的内容
                $('.row').renderValues(data.strategyComment, {
                    'setHref': function (item, value) {
                        $(item).attr('href', $(item).data('href') + value);

                    },
                    'getStar': function (item, value) {
                        // 拼接星星html
                        var starHtml = '';
                        var unStarHtml = '';
                        var num = parseInt(value); // 将字符串类型value解析为int类型
                        // 迭代拼接html
                        for (var i = 0; i < value; i++) {
                            starHtml += '<i class="fa fa-star"></i>';
                        }
                        for (var i = num; i < 5; i++) {
                            unStarHtml += '<i class="fa fa-star-o"></i>';
                        }
                        // 拼接html
                        $('.comment-star').append(starHtml);
                        $('.comment-star').append(unStarHtml);
                    },
                    'setSCHref': function (item, value) {
                        $(item).attr('href', $(item).data('href') + value);
                    }
                });
                // 迭代图片数组
                var html = '';
                $.each(data.imgUrlsArr, function (index, item) {
                    html += '<li><img src="'+item+'"></li>';
                })
                // 拼接html
                $('.comment-img').html(html);
                //图片点击
                $(".comment-img img").click(function () {
                    $(document).dialog({
                        titleShow: false,
                        overlayClose: true,
                        content: '<div style="text-align: center;"><img width="100%" src="'+$(this).attr('src')+'"></div>'
                    });
                })

            })
            // ==================================刘涛===============================================
            // 用于开发攻略点评点赞
            // 获取当前攻略点评点赞数
            $.get('/strategyComments/'+id+'/num',function (data) {
                //将点赞数设置到网页上
                $('#likeNum').html(data);
            })
            $('.likeBtn').click(function () {
                // 发送ajax请求判断当前用户是否登录
                $.get('/strategyComments/isLogin',function (data) {
                    if (data.state==1) {
                        // 进行点赞逻辑开发
                        $.ajax({
                            url:'/strategyComments/like',
                            type:'post',
                            data:{strategyCommentId:id},
                            success:function (data) {
                                //将点赞数设置到网页上
                                $('#likeNum').html(data);
                            }
                        })

                    }else{
                        // 跳转到登录页面
                        window.parent.location.href='/login.html';
                    }
                })
            })
            // ===============end================
        })
    </script>


</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="/index.html">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>点评详情</span>
        </div>
        <div class="col"></div>
    </div>
</div>

<div class="comment">


    <div class="container ">
        <div class="row">
            <div class="col-2 comment-head">
                <a href="userProfiles.html?id=" render-fun="setHref" render-key="user.id">
                    <img class="rounded-circle" render-src="user.headImgUrl">
                    <span render-html="user.nickName"></span>
                </a>
                <button class="btn" id="followBtn"><i class="fa fa-hand-o-right"> </i> 关注</button>
            </div>
            <div class="col">
							<span class="comment-star" render-fun="getStar" render-key="starNum">
							</span>

                <span class="comment-date" render-html="createTime"></span>
                <!--渲染攻略点评内容-->
                <div class="comment-content">
                    <p render-html="content"></p>
                </div>
                <!--拼接html攻略点评图片-->
                <div id="imgUrls">
                    <ul class="comment-img">

                    </ul>

                </div>


                <!--渲染攻略链接-->
                <div class="comment-link">
                    <a data-href="strategyCatalogs.html?id=" render-fun="setSCHref" render-key="strategy.id">
                        <img render-src="strategy.coverUrl"> <span render-html="strategy.title"></span>
                        <i class="fa fa-angle-right fa-2x"></i>
                    </a>
                </div>

            </div>
        </div>
    </div>

    <div class="count d-flex justify-content-between">
        <div class="p-2">评论<span>0</span></div>
        <div class="p-2 likeBtn" title="赞" style="color: #00c800">赞<span id="likeNum"></span></div> <!--开发攻略点评点赞-->
    </div>

</div>

<div class="comment-list">
    快来发表你的评论吧
</div>

<div class="operation">
    <div class="d-flex justify-content-between">
        <div class="p-2"><i class="fa fa-commenting-o"></i> 添加你的评论</div>
        <div class="p-2"><i class="fa fa-star-o"></i> 收藏</div>
    </div>
</div>


</body>

</html>